function refresh_vcode()
    {
        var $img_vcode = $("#img_vcode");
        $img_vcode.empty().append('<img src="/vcode?t='+Math.random()+'" />');  
    }
    
$(document).ready(function(){
    
    
    $('#aReVcode,#img_vcode').click(function(){
        setTimeout('refresh_vcode()',100);
        return false;
    });
    
    $('input').focus(function(){
        $id = $(this).attr('id');
        $id = "#alert_"+$id.replace('ipt' , '').toLowerCase();
        $($id).empty();
        
    });
    
    $('#btnApply').click(function(){
        $_name = $('#iptName').val();
        if($_name == "")
        {
            $('#alert_name').empty().append($tl_lang.pApplyAltNameNull);
            return false;
        }
        $_company = $('#iptCompany').val();
        if($_company == "")
        {
            $('#alert_company').empty().append($tl_lang.pApplyAltCompanyNull);
            return false;
        }
        $_email = $('#iptEmail').val();
        if($_email == "")
        {
            $('#alert_email').empty().append($tl_lang.pApplyAltEmailNull);
            return false;
        }
        else if (!/\b(^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*$)\b/.test($_email))
        {
            $('#alert_email').empty().append($tl_lang.pApplyAltEmailWrong);
            return false;
        }
        $_phone = $('#iptPhone').val();
        if($_phone == "")
        {
            $('#alert_phone').empty().append($tl_lang.pApplyAltPhoneNull);
            return false;
        }
        $_fax = $('#iptFax').val();
        if($_fax == "")
        {
            $('#alert_fax').empty().append($tl_lang.pApplyAltFaxNull);
            return false;
        }
        $_message = $('#iptMessage').val();
        $_vcode = $('#iptVcode').val();
        if($_vcode == "")
        {
            $('#alert_vcode').empty().append($tl_lang.pApplyAltVcodeNull);
            return false;
        }
        
        $.post(
	       '/api/member_apply',
	       'name=' + bsUrlencode($_name)
	           + '&company=' + bsUrlencode($_company)
	           + '&email=' + bsUrlencode($_email) 
	           + '&mobile=' + bsUrlencode($_phone) 
	           + '&fax=' + bsUrlencode($_fax) 
	           + '&message=' + bsUrlencode($_message) 
	           + '&vcode=' + bsUrlencode($_vcode),
	       function($result)
	       {
	           var $rs = bsFormatApiRs($result);
	           if(!bsIsApiSystemError($rs.code))
	           {
	               if($rs.code == $bsSystemCode.success)
	               {
    	               alert($tl_lang.pApplySuc);
    	               setTimeout(function(){window.location='/';},3000);
	               }
	               else
	               {
	                   $('#aReVcode').click();
	                   alert(eval('$tl_lang.pApplyAltErr.'+$rs.code),null,{title: 'Message'});
	               }
	           }
	           else
	           {
	               $('#aReVcode').click();
	           }
	       }
	    );
	    return false;
    });
});